﻿// Copyright (C) 2009  Lex Li
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

/*
 * Created by SharpDevelop.
 * Date: 10/1/2009
 * Time: 5:37 PM
 */
namespace Lextm.M8Pack.Components
{
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;
    
    /// <summary>
    /// Description of Shortcut.
    /// </summary>
    public class Shortcut : DrawingArea
    {
        private Image _image;

        [Bindable(true)]
        public Image Image
        {
            get { return _image; }
            set
            {
                _image = value;
                if (_image != null)
                {
                    Width = _image.Size.Width;
                    Height = _image.Size.Height;
                }
                
                Invalidate();
            }
        }
                
        protected override void OnMouseEnter(EventArgs e)
        {
            if (Visible && _image == Properties.Resources.document_open)
            {
                Cursor = Cursors.Hand;
            }
            
            base.OnMouseEnter(e);
        }
        
        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);
            Cursor = Cursors.Default;
        }
        
        protected override void OnDraw(Graphics graphics)
        {
            if (_image == null)
            {
                return;
            }
            
            if (!Visible)
            {
                return;
            }
            
            graphics.DrawImage(_image, new PointF(0f, 0f));
        }
    }
}
